package com.lele.ui.check;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JComboBox;
import javax.swing.JTextField;

import com.lele.ui.UI_v2;

public class CheckField extends UI_v2 {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static  Map<String, String> checkField() {
		Map<String, String> map = new HashMap<String, String>();
		List<String> cbs = new ArrayList<String>();
		List<String> tfs = new ArrayList<String>();
		List<String> names = new ArrayList<String>();
		for (int i = 0; i < jPanel2.getComponents().length; i++) {
			Object obj = jPanel2.getComponent(i);
			if (obj instanceof JTextField
					&& !((JTextField) jPanel2.getComponent(i)).getText()
							.toString().equals("")) {
				tfs.add(((JTextField) jPanel2.getComponent(i)).getText()
						.toString());
				names.add(((JTextField) jPanel2.getComponent(i)).getName());
			} else if (obj instanceof JComboBox
					&& !((JComboBox<?>) jPanel2.getComponent(i))
							.getSelectedItem().toString().equals("类型")) {
				cbs.add(((JComboBox<?>) jPanel2.getComponent(i))
						.getSelectedItem().toString());
			}
		}
		for (int i = 0; i < tfs.size(); i++) {
			if (names.get(i) != null) {
				map.put(tfs.get(i), cbs.get(i) + "|PK");
			} else {
				map.put(tfs.get(i), cbs.get(i));
			}
		}

		List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(
				map.entrySet());
		// 排序前
		for (int i = 0; i < infoIds.size(); i++) {
			String id = infoIds.get(i).toString();
			System.out.println(id);
		}
		// 排序
		Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
			public int compare(Entry<String, String> o1,
					Entry<String, String> o2) {
				return (o2.getValue().length() - o1.getValue().length());
			}
		});
		// 排序后
		for (int i = 0; i < infoIds.size(); i++) {
			String id = infoIds.get(i).toString();
			System.out.println(id);
		}

		return map;
	}

}
